package main

import (
	"encoding/json"
	"fmt"
)

type Teacher struct {
	Name  string            `json:"name"` //结构体标签
	Age   int               `json:"age"`
	Hobby []string          `json:"hobby"`
	Map1  map[string]string `json:"map1"`
}

func main() {
	fmt.Println("-----------------------------------------------")
	map1 := make(map[string]string)
	map1["name"] = "产黑"
	var t1 = Teacher{Name: "陈浩杰",
		Age:   20,
		Hobby: make([]string, 0),
		Map1:  map1,
	}

	marshal, err := json.Marshal(t1)
	if err != nil {
	}
	fmt.Println(string(marshal))

	var str = `{"name":"陈浩杰","age":20,"hobby":["1","2","2"],"map1":{"name":"产黑"}}`

	var t2 Teacher
	err = json.Unmarshal([]byte(str), &t2)
	if err != nil {
	}
	fmt.Printf("%#v\n", t2)
}
